package com.leyou.common.util;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zqq
 * @ClassName UrlUtils
 * @Description
 * @date 2020/3/10-11:27
 */
public class UrlUtils {

    private final static PathMatcher MATCHER = new AntPathMatcher();

    /**
     * @Title: check
     * @Description: 验证url是否匹配
     * @author: zqq
     * @param paths url集合
     * @param url 要验证的url
     * @return: boolean
     * @createTime: 2020-03-10 11:40
     * @version: v.1.0
     */
    public static boolean check(List<String> paths, String url) {
        for (String path : paths) {
            if(MATCHER.match(path,url)){
                return true;
            }
        }
        return  false;
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("/user/author/query/permission/*");
        boolean bool = UrlUtils.check(list,"/user/author/query/permission/2/a");
        System.out.println(bool);
    }
}
